<template>
    <div class="acceptance-registration-increase">
        
            <!-- 新增弹窗 -->
        <a-modal
        class="flow-path-model-box manufacturing-taskAcceptance-increase"
        :visible="visibleShow" 
        :title="'新增专项审评'"
        :maskClosable="false"
        :destroyOnClose="true"
        :forceRender="true"
        @cancel="visibleShow = false"
        width="100%"
        wrapClassName="acceptance-full-modal"
        :footer="null"
        >
            <a-spin size="large" :spinning="modalSpinningPrice" :key="spinningKey" tip="正在加载中...">
                <div class="reviewVerificationManage-allHandlingPage-modal-v">
                    <div class="top-handle-v">
                        <div style="font-weight: 600;font-family: KaiTi !important;color: #38f;display: flex;align-items: center;">
                            <!-- <div>
                                <span style="display: inline-block;border:2px solid #ff9200;padding: 0 5px;border-radius: 17.3px;color: #ff9200;margin-right: 10px;font-size: 18px;">{{ parameterData.fhjmc }}</span>
                                <span>{{ parameterData.fqymc }}</span>
                            </div>
                            <span v-if="parameterData.fslbh" style="display: inline-block;border:2px solid #4eef66;padding: 0 5px;border-radius: 17.3px;color: #4eef66;margin-left: 10px;font-size: 14px;">{{ parameterData.fslbh }}</span> -->
                        </div>
                        <div style="display: flex;align-items: center;">
                            <div v-if="!parameterData.isHandle">
                                <!-- <a-button @click="returnGovernmentServices('returnZwfwxt')" icon="rollback">退回政务服务</a-button> -->
                                <a-button style="margin-left: 10px;" class="blue-btn" type="primary" icon="save" @click="preserveHandling()">保存</a-button>
                                <a-button style="margin-left: 10px;" class="blue-btn" type="primary" icon="check-circle" @click="linkHandling('spcysubmitFlow')">提交</a-button>
                                <!-- <a-button style="margin-left: 10px;" class="blue-btn" type="primary" icon="retweet" @click="departmentTransfer('innerChangeFlowJob')">转办到科室</a-button> -->
                                <!-- <a-button style="margin-left: 10px;" class="blue-btn" type="primary" icon="interaction" @click="internalTransferClick('spcytransferFlowJob')">内部转办</a-button> -->
                                
                            </div>
                            <div style="margin-left: 50px;">
                                <a-button class="blue-btn" type="primary" v-if="!parameterData.isHandle" icon="reload" @click="refreshClick()">刷新</a-button>
                                <!-- <a-button style="margin-left: 10px;" @click="returnClick()" icon="close"></a-button> -->
                            </div>
                        </div>
                    </div>
                    <div style="width: 100%;height: 8px;"></div>
                    <div style="width: 100%;display: flex;" >
                        <!-- <div style="height: calc(100vh - 70px);width: 140px;background-color: #fff;padding: 10px;">
                            <commpStep :parameterData="{index:0}"></commpStep>
                        </div> -->
                        <!-- style="width: calc(100% - 150px);margin-left: 10px;" -->
                        <div style="width: 100%;">
                            <eventSet
                            :key="eventSetKey" 
                            ref="eventSetRef" 
                            :parameter="parameterData" 
                            @successReturn="successReturn" 
                            @updatedSuccess="updatedSuccess"
                            @cancelLoadingTrue="cancelLoadingTrue"
                            @cancelLoadingFalse="cancelLoadingFalse"
                            @linkHandlingReturn="linkHandlingReturn"
                            />
                        </div>
                        
                    </div>
                </div>
            </a-spin>
            <processingConditionsAll ref="processingConditionsAllRef" :processingData="processingData" @interfaceSuccessful="interfaceSuccessful"></processingConditionsAll>
            <supplementaryRectification ref="supplementaryRectificationRef" @rectificationSuccess="rectificationSuccess"/>
            <multipleTaskPrompts ref="multipleTaskPromptsRef" />
        </a-modal>
    </div>
</template>
<script>

import {spcyaddSqsxBasic,innerChangeFlowJob,hbjcgetXtsxHjmcSqsxList,spcyGetJobConcernByJobId,addServe,} from './service/index'
import compSelector from '@/components/compSelector/compSelector'
import eventSet from './eventSet.vue'
import multipleTaskPrompts from "../taskAcceptance/multipleTaskPrompts.vue";
import moment from 'moment'
export default {
    components:{
        compSelector,
        eventSet,
        multipleTaskPrompts,
    },
    props:{
        addEditParameter:{
            type:[Array,Object],
            default: () => {},
            required:false
        }
    },
    data(){
        return{
            moment:moment,
            processingData:{},
            typeSelect:'Select',
            visibleShow:false,
            confirmLoading:false,
            formState:{ksfl:''},
            formRequer:'',
            spinningKey:null,
            submittedSuccessfully:false,
            parameterData:{},
            eventSetKey:null,
            modalSpinningPrice:null,
        }
    },
    computed: {
        // modalSpinningPrice(){
        //     return this.$store.state.permission.modalSpinningPrice
        // },
    },
    watch:{
        addEditParameter: {
            handler (newval, oldVal) {
                this.cancelLoading()
                //console.log('获取到了什么',newval)
                this.parameterData = newval
                this.formState.ksfl = ''
                // if(!newval.sqsxid){
                //     spcyaddSqsxBasic({fywflcode:'001002'}).then(res=>{
                //         //console.log(res)
                //         //console.log('有进来这里吗？',res)
                //         if(res.code == 200){
                //             this.parameterData.sqsxid = res.result.sqsx.id
                //             this.parameterData.jobid = res.result.job.id
                //             this.parameterData.nextNode  = res.result.nextNode
                //             this.parameterData.nextNodeDbrList = res.result.nextNodeDbrList
                //         }
                //     })
                // }
            },
            deep: true
        },
        
    },
    methods:{
        getData(val){
            this.modalSpinningPrice = true
            //console.log(val,88888888888)
            if(!val.sqsxid){
                // spcyaddSqsxBasic({fywflcode:'001002'}).then(res=>{
                //     //console.log(res)
                //     //console.log('有进来这里吗？',res)
                //     if(res.code == 200){
                //         this.parameterData.sqsxid = res.result.sqsx.id
                //         this.parameterData.jobid = res.result.job.id
                //         this.parameterData.nextNode  = res.result.nextNode
                //         this.parameterData.nextNodeDbrList = res.result.nextNodeDbrList
                //         val.sqsxid = res.result.sqsx.id
                //         val.jobid = res.result.job.id
                //         val.nextNode = res.result.nextNode
                //         val.nextNodeDbrList = res.result.nextNodeDbrList
                //         this.$nextTick(()=>{
                //             this.$refs.eventSetRef.getDatas(val)
                //         })
                //     }
                // })
                this.$nextTick(()=>{
                    this.$refs.eventSetRef.getDatas(val)
                })
            }else{
                this.$nextTick(()=>{
                    this.$refs.eventSetRef.getDatas(val)
                    
                })
                this.parameterData = val
            }
            
        },
        cancelFalse(){
            this.cancelLoading()
        },
        cancelLoadingTrue(){
            this.$store.dispatch('UpdateSpinningPrice', {key:'true',stateKey:'modalSpinningPrice'})
        },
        cancelLoadingFalse(){
            this.$store.dispatch('UpdateSpinningPrice', {key:false,stateKey:'modalSpinningPrice'})
        },
        updatedSuccess(){//有触发说明已经加载完成
            //console.log('有触发说明已经加载完成')
            // this.cancelLoading()
            // this.parameterData
            this.modalSpinningPrice = false
            // hbjcgetXtsxHjmcSqsxList({jobid:this.parameterData.jobid}).then(res=>{
            //     if(res.code == 200){
            //         //console.log('我获取到了什么提示列表',res)
            //         if(res.result && res.result.records.length){
            //             // this.$refs.multipleTaskPromptsRef.getData(res.result?res.result.records:[])
            //             this.$refs.multipleTaskPromptsRef.getData(res.result?res.result.records:[])
            //             this.$refs.multipleTaskPromptsRef.visible = true
            //         }
            //     }
            // })
            
        },
        cancelLoading(){
            //console.log('我再刷新')
            this.$store.dispatch('UpdateSpinningPrice', {key:true,stateKey:'modalSpinningPrice'})
        },
        returnClick(){//返回
            this.visibleShow = false
        },
        refreshClick(){
            this.parameterData = this.$refs.eventSetRef.$refs.dealWithRef.formState
        },
        transferClick(){//转办
            var that = this
            if(this.formState.ksfl){
                this.$confirm({
                    title:'您确认要转办吗？',
                    // icon: createVNode(ExclamationCircleOutlined),
                    onOk() {
                        innerChangeFlowJob({jobid:that.parameterData.jobid,ksfl:that.formState.ksfl}).then(res=>{
                            if(res.code == 200){
                                that.$store.dispatch('UpdateSpinningPrice', 
                                {key:true,stateKey:'modalSpinningPrice'}).then(() => {
                                    that.successReturn(false)
                                    that.$message.success(res.message)
                                })
                                
                            }else{
                                that.$store.dispatch('UpdateSpinningPrice', {key:false,stateKey:'modalSpinningPrice'})
                                that.$message.warning(res.message)
                            }
                        })
                    },
                    
                });
            }else{
                this.$message.warning('请选择转办科室')
            }
            
        },
        preserveClick(){//保存
            // this.$store.dispatch('UpdateSpinningPrice', {key:'true',stateKey:'modalSpinningPrice'})
            this.$refs.dealWithRef.handlePreserve()
        },
        submitClick(){//提交
            // this.$store.dispatch('UpdateSpinningPrice', {key:'true',stateKey:'modalSpinningPrice'})
            this.$refs.dealWithRef.shandleSubmit()
        },
        linkHandlingReturn({val,row,type}){
        //console.log(val,row,type)
            if(row){
                this.addEditParameter = row
                this.parameterData = row
                this.$emit('successReturn')
            }
            if(type == '提交'){
                this.$refs.processingConditionsAllRef.processingConditionsVisible = true
                let data = {
                    interface:'spcysubmitFlow',
                    sqsxid:this.addEditParameter.sqsxid,
                    nextNodeDbrList:this.addEditParameter.nextNodeDbrList,
                    nextNode:this.addEditParameter.nextNode,
                    jobid:this.addEditParameter.jobid,
                    headerLeftTitle:'提交',
                    headerCenterTitle:'药品生产查验--任务受理',
                }
                this.processingData = data
                this.$refs.processingConditionsAllRef.getData(data)
            }
        },
        successReturn(val,row,type){
            //console.log('type得到什么类型',val,row,type)
            if(row){
                this.addEditParameter = row
                this.parameterData = row
            }
            this.visibleShow = val
            
            this.$emit('successReturn')
        },
        interfaceSuccessful(val){
            this.successReturn(val)
        },
        rectificationSuccess(){
            this.successReturn(false)
        },
        preserveHandling(){
            //console.log()
            if(!this.addEditParameter.sqsxid){
                this.$refs.eventSetRef.$refs.dealWithRef.handlePreserve(1)
            }else{
                this.$refs.eventSetRef.$refs.dealWithRef.handlePreserve()
            }
        },
        linkHandling(val){
            //console.log('提交')
            let result = this.$refs.eventSetRef.$refs.dealWithRef.shandleSubmit('提交')
            //console.log('提交',result)
            // let result = this.addEditParameter = this.$refs.eventSetRef.$refs.dealWithRef.formState
            let formData = this.$refs.eventSetRef.$refs.dealWithRef.formState
            let obj = {
                jobid:formData.jobid,
                sqsxid:formData.sqsxid,
                opinion:formData.opinion,
                smgflag:'否',
                map:{
                    fsxmc:formData.fsxmc,
                    fslzt:formData.fslzt,
                    fslsj:formData.fslsj?moment(formData.fslsj).format('YYYY-MM-DD HH:mm:ss'):'',
                    fslbh:formData.fslbh,
                    fwcsx:formData.fwcsx,
                    fcyjcfw:formData.fcyjcfw,
                    fjcdd:formData.fjcdd,
                    fqyid:formData.fqyid,
                    fqymc:formData.fqymc,
                    ftyshxydm:formData.ftyshxydm,
                    fqyfddbrfzr:formData.fqyfddbrfzr,
                    fqylxr:formData.fqylxr,
                    fqylxrdh:formData.fqylxrdh,
                    fqyzszcdz:formData.fqyzszcdz,
                    fszdq:formData.fszdq,//
                    fxxdz:formData.fxxdz,
                    ffzrsfzh:formData.ffzrsfzh,
                    ffzrlxfs:formData.ffzrlxfs,
                    fscdz:formData.fscdz,
                    fscfw:formData.fscfw,
                    fqyxkzh:formData.fqyxkzh,
                    fqyxkzyxq:formData.fqyxkzyxq?moment(formData.fqyxkzyxq).format('YYYY-MM-DD'):'',
                    fsxjclx:formData.fsxjclx,
                    fscxcj:formData.fscxcj,
                    fjcpz:formData.fjcpz,

                    
                    fcykssj:moment(formData.inspectionDateArr[0]).format('YYYY-MM-DD'),
                    fcyjssj:moment(formData.inspectionDateArr[1]).format('YYYY-MM-DD'),
                    frwly:formData.frwly,
                    fyyxsjcbcxx:formData.fyyxsjcbcxx,
                    fjcsjfw:formData.fjcsjfw,
                    fsfsjztsc:formData.fsfsjztsc,
                    fztscwylj:formData.fztscwylj,
                    fsfsjhfsc:formData.fsfsjhfsc,
                    fhfscwylj:formData.fhfscwylj,
                    fsftyksld:formData.fsftyksld,
                    fxzjgdxlx:formData.fxzjgdxlx,
                    fsfsjjtcj:formData.fsfsjjtcj,
                    fsfsjjtscx:formData.fsfsjjtscx,
                    fjx:formData.fjx,
                    fgg:formData.fgg,
                    fdjh:formData.fdjh,
                    fxxdz:formData.fxxdz,
                    fcj:formData.fcj,
                    fscx:formData.fscx,
                    fjgsx:formData.fjgsx,
                    fjcxs:formData.fjcxs,
                    fjclb:formData.fjclb,
                    fjcfs:formData.fjcfs,
                    fsftc:formData.fsftc,
                }
                
            }
            if(result){
                
                if(!this.parameterData.sqsxid){
                    spcyaddSqsxBasic({fywflcode:'001002'}).then(res=>{
                        if(res.code == 200){
                            
                            addServe(obj).then(res2=>{
                                if(res2.code == 200){
                                    this.parameterData.sqsxid = res2.result.sqsx.id
                                    this.parameterData.jobid = res2.result.job.id
                                    this.parameterData.nextNode  = res2.result.nextNode
                                    this.parameterData.nextNodeDbrList = res2.result.nextNodeDbrList
                                    this.$refs.processingConditionsAllRef.processingConditionsVisible = true
                                    let data = {
                                        interface:val,
                                        sqsxid:this.parameterData.sqsxid,
                                        nextNodeDbrList:this.parameterData.nextNodeDbrList,
                                        nextNode:this.parameterData.nextNode,
                                        jobid:this.parameterData.jobid,
                                        headerLeftTitle:'提交',
                                        headerCenterTitle:'药品生产查验--专项审评',
                                    }
                                    this.processingData = data
                                    this.$refs.processingConditionsAllRef.getData(data)
                                }else{
                                    this.$message.warning(res2.message)
                                }
                            })
                            
                        }else{
                            this.$message.warning(res.message)
                        }
                    })
                }else{
                    addServe(obj).then(res2=>{
                        if(res2.code == 200){
                            //console.log('我在提交',res2)
                            // this.parameterData.sqsxid = res2.result.sqsx.id
                            // this.parameterData.jobid = res2.result.job.id
                            // this.parameterData.nextNode  = res2.result.nextNode
                            // this.parameterData.nextNodeDbrList = res2.result.nextNodeDbrList
                            this.$refs.processingConditionsAllRef.processingConditionsVisible = true
                            let data = {
                                interface:val,
                                sqsxid:this.parameterData.sqsxid,
                                nextNodeDbrList:this.parameterData.nextNodeDbrList,
                                nextNode:this.parameterData.nextNode,
                                jobid:this.parameterData.jobid,
                                headerLeftTitle:'提交',
                                headerCenterTitle:'药品生产查验--专项审评',
                            }
                            this.processingData = data
                            this.$refs.processingConditionsAllRef.getData(data)
                        }else{
                            this.$message.warning(res2.message)
                        }
                    })
                }
                
            }
        },
        departmentTransfer(val){
            this.$refs.eventSetRef.$refs.dealWithRef.handlePreserve()
            this.$refs.processingConditionsAllRef.processingConditionsVisible = true
            let data = {
                interface:val,
                sqsxid:this.addEditParameter.sqsxid,
                jobid:this.addEditParameter.jobid,
                isBlyj:false,
                isZbxx:true,
                isXyb:false,
                headerLeftTitle:'转办到科室',
                headerCenterTitle:'药品生产查验--任务受理',
            }
            this.processingData = data
            this.$refs.processingConditionsAllRef.getData(data)
        },
        //内部转办
        internalTransferClick(val){
            this.$refs.eventSetRef.$refs.dealWithRef.handlePreserve()
            this.$refs.processingConditionsAllRef.processingConditionsVisible = true
            let data = {
                interface:val,
                sqsxid:this.addEditParameter.sqsxid,
                jobid:this.addEditParameter.jobid,
                isBlyj:true,
                isZbxx:false,
                isXyb:false,
                isNbbl:true,
                isBlr:false,
                NoViewBlr:true,
                headerLeftTitle:'内部转办',
                headerCenterTitle:'药品生产查验--任务受理',
            }
            this.processingData = data
            this.$refs.processingConditionsAllRef.getData(data)
        },
        returnGovernmentServices(val){
            this.$refs.supplementaryRectificationRef.visible = true
            this.$refs.supplementaryRectificationRef.getData(
                {interfaceValue:val,modalTitle:'退回政务服务',isTextMessage:false,sqsxid:this.addEditParameter.sqsxid,
                isTime:false,jobid:this.addEditParameter.jobid},
                {opinion:'thyy'}
            )
        },
    }

}

</script>
<style lang="less">
/* .ant-form-item-label{
    font-weight: 600;
} */

//  .ant-modal-title{
//     font-weight: 600;
//  }
//  .ant-modal-header{
//     background: #5ca3e5;
//  }
//  .ant-modal-footer .ant-btn-primary{
//     border: 1px solid #5ca3e5 !important;
//     background-color: #5ca3e5 !important;
//     color: #fff !important;
//  }
// //  .acceptance-modal .ant-modal-header{
// //     display: none !important;
// //  }
//  .acceptance-modal .ant-modal-footer{
//     display: none !important;
//  }
//  .acceptance-modal .ant-modal-content{
//     height: 100vh;
//     overflow: auto;
//  }
.manufacturing-taskAcceptance-increase{
    .ant-modal {
    max-width: 100%;
    top: 0;
    padding-bottom: 0;
    margin: 0;
  }
  .ant-modal-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    height: calc(100vh);
  }
  .ant-modal-body {
    flex: 1;
    padding: 0px;
    background: #f4f7fc !important;
    height: calc(100vh - 50px);
  }
}

</style>